﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using Phone.Framework.Data;

namespace Phone.Framework.Behaviors
{
    public class BingImageLoadBehavior : Behavior<Image>
    {
        protected override void OnAttached()
        {
            base.OnAttached();
        }

        public string Key
        {
            get { return (string)GetValue(KeyProperty); }
            set { SetValue(KeyProperty, value); }
        }

        public static readonly DependencyProperty KeyProperty =
            DependencyProperty.Register("Key", typeof(string), typeof(BingImageLoadBehavior),
            new PropertyMetadata(string.Empty, (s, a) =>
            {
                var behavior = s as BingImageLoadBehavior;

                BingImageSearch.SearchBingImage(behavior.AssociatedObject, behavior.Key);
            }));



        public string Url
        {
            get { return (string)GetValue(UrlProperty); }
            set { SetValue(UrlProperty, value); }
        }

        public static readonly DependencyProperty UrlProperty =
            DependencyProperty.Register("Url", typeof(string), typeof(BingImageLoadBehavior),
            new PropertyMetadata(string.Empty, (s, a) =>
            {
                var behavior = s as BingImageLoadBehavior;
                LowProfileImageLoader.SetUriSource(behavior.AssociatedObject,new Uri(behavior.Url));
               // BingImageSearch.UrlToSource(behavior.AssociatedObject, behavior.Url);
            }));
    }
}
